#ifndef IEC10X_FRAME_H
#define IEC10X_FRAME_H

typedef struct IEC10X_FRAME
{
    unsigned char data[256];
} IEC10X_Frame_T;

typedef enum
{
    IEC10X_REASON_ACTIVATION_CONFIRM = 0x07, //激活确认
    IEC10X_REASON_ACTIVATION_TERMINATE = 0x0A, //激活终止
} IEC10X_REASON;

typedef enum
{
    IEC10X_Frame_FMT_UNKNOWN,
    IEC10X_Frame_FMT_I,
    IEC10X_Frame_FMT_S,
    IEC10X_Frame_FMT_U,
} IEC10X_Frame_FMT;

typedef enum
{
    IEC10X_QDS_NONE = 0xFF,
} IEC10X_QDS;

const IEC10X_Frame_T* IEC10X_FRAME_STARTDT();
const IEC10X_Frame_T* IEC10X_FRAME_STARTDT_ACK();
const IEC10X_Frame_T *IEC10X_FRAME_TESTFR();
const IEC10X_Frame_T *IEC10X_FRAME_TESTFR_ACK();

//清除整帧数据
void IEC10X_Frame_Clear(IEC10X_Frame_T* self);
//判等
int IEC10X_Frame_IsEqual(const IEC10X_Frame_T* frame1, const IEC10X_Frame_T* frame2);
//信息对象是否连续
int IEC10X_Frame_IsObjContinuous(const IEC10X_Frame_T* self) ;

//计算整帧字节数
int IEC10X_Frame_Bytes(const IEC10X_Frame_T* self);

//获取帧的命令字
unsigned char IEC10X_Frame_Cmd(const IEC10X_Frame_T* self);
//获取帧长度
int IEC10X_Frame_Length(const IEC10X_Frame_T* self);
//获取帧格式
IEC10X_Frame_FMT IEC10X_Frame_Fmt(const IEC10X_Frame_T* self);
//获取接收序号
unsigned short IEC10X_Frame_RecvID(const IEC10X_Frame_T* self);
//获取发送序号
unsigned short IEC10X_Frame_SendID(const IEC10X_Frame_T* self);
//获取公共地址
short IEC10X_Frame_Addr(const IEC10X_Frame_T* self);
//获取信息对象数量
int IEC10X_Frame_ObjNum(const IEC10X_Frame_T* self);
//获取时标
long long IEC10X_Frame_Time(const IEC10X_Frame_T* self);

//设置帧命令字
void IEC10X_Frame_SetCmd(IEC10X_Frame_T* self, unsigned char cmd);
//设置传送原因
void IEC10X_Frame_SetReason(IEC10X_Frame_T* self, IEC10X_REASON reason);
//添加一个对象
void IEC10X_Frame_AddObject(IEC10X_Frame_T* self, int obj_addr, unsigned char obj_val, IEC10X_QDS qds);
//设置序号
void IEC10X_Frame_SetID(IEC10X_Frame_T* self, unsigned short recv_id, unsigned short send_id);
//设置公共地址
void IEC10X_Frame_SetAddr(IEC10X_Frame_T* self, short addr);

#endif // IEC10X_FRAME_H
